package top.lixunda.ecommerce.server.good.api.entity.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.ecommerce.server.good.api.entity.db.SysStoreCategoryDO;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 普通类型的店铺目录
 *
 * @author Xumda
 * @version time:2020/1/11 10:56
 */
@SuppressWarnings("WeakerAccess")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class SysStoreCategoryVO {

    /**
     * 主键ID
     */
    private Integer id;

    /**
     * 名称
     */
    private String name;

    /**
     * 描述
     */
    private String description;

    /**
     * 是否叶节点
     */
    private Integer isLeaf;

    /**
     * 是否根节点
     */
    private Integer isRoot;

    /**
     * 父节点
     */
    private Integer parentId;

    /**
     * 转换
     */
    public static SysStoreCategoryVO fromStoreCategoryDO(SysStoreCategoryDO sysStoreCategoryDO) {
        if (sysStoreCategoryDO == null) {
            return null;
        }
        SysStoreCategoryVO vo = new SysStoreCategoryVO();
        BeanUtils.copyProperties(sysStoreCategoryDO, vo);
        return vo;
    }

    /**
     * 转换
     */
    public static List<SysStoreCategoryVO> fromStoreCategoryDO(List<SysStoreCategoryDO> list) {
        if (list == null) {
            return null;
        }
        return list.stream()
                .map(SysStoreCategoryVO::fromStoreCategoryDO)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }

}
